package org.example.controller;

import org.example.entity.User;
import org.example.exception.ErrorEnum;
import org.example.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    UserService userService;

    @PostMapping("/login")
    public Map<String, Object> login(User user, HttpSession session) {
        return userService.login(user,session);
    }

    @GetMapping("/session")
    public Map<String, Object> checkSession() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", ErrorEnum.SUCCESS.getCode());
        map.put("message", ErrorEnum.SUCCESS.getMessage());
        return map;
    }
}
